#
# @lc app=leetcode.cn id=1814 lang=python3
#
# [1814] 统计一个数组中好对子的数目
#

# @lc code=start
from collections import defaultdict
from typing import List

# nums[i] + rev(nums[j]) == nums[j] + rev(nums[i])
# nums[i] - rev(nums[i]) == nums[j] - rev(nums[j])
#该题的关键就是将题目的条件转化， 将下标相同的放到一块处理
class Solution:
    def rev(self,x : int) -> int:
        s = 0
        while x:
            s = s * 10+ x%10
            x //= 10
        return s
    def countNicePairs(self, nums: List[int]) -> int:
        mod = 1_0000_00007
        ans = 0
        cnt = defaultdict(int)
        for x in nums:
            y = self.rev(x)
            tag = x - y
            if tag in cnt:
                ans = (ans + cnt[tag]) % mod
            cnt[tag] += 1
        return ans
# @lc code=end

